package fr.upmc.i3s.upmcontact.tools;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;

public class MobileDataUtils {
	
	private static final String TAG = "MobileDataUtils";
	
	public static final int CONNECTIVITY_NONE = -1;

	public static int getCurrentNetworkType(Context context) {
		ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		String display = null;
		int result = CONNECTIVITY_NONE;
		NetworkInfo info = (connectivity != null ? connectivity.getActiveNetworkInfo() : null);
		if (info != null) {
			display = info.getTypeName();
			result = info.getType();
		}
		Log.v(TAG, "activeNetworkType: " + display);
		return result;
	}
	
	public static boolean isNetworkAvailable(Context context) {
		return getCurrentNetworkType(context) != CONNECTIVITY_NONE;
	}
	
}
